//
//  HomeQuestionCompulsoryEndTestAlertView.m
//  ZJControlsClass
//
//  Created by mac on 2024/12/7.
//

#import "HomeQuestionCompulsoryEndTestAlertView.h"


@interface HomeQuestionCompulsoryEndTestAlertView ()

@property (nonatomic,strong) UIImageView * img;
@property (nonatomic,strong) UIButton * dissmissBtn;
@property (nonatomic,strong) UILabel * titleLabel;
@property (nonatomic,strong) UILabel * msgLabel;

@property (nonatomic,strong) UILabel * totalNumLabel;
@property (nonatomic,strong) UILabel * testTypeLabel;

@property (nonatomic,strong) UIView * follewView;
@property (nonatomic,strong) UILabel * totalLabel;
@property (nonatomic,strong) UILabel * tureLabel;
@property (nonatomic,strong) UILabel * falseLabel;
@property (nonatomic,strong) UILabel * otherLabel;

@property (nonatomic,strong) UIButton * knowBtn;
@property (nonatomic,strong) UIButton * lookBtn;


@end



@implementation HomeQuestionCompulsoryEndTestAlertView



- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self){
        
        [self configUI];
    }
    
    return self;
}

-(void)configUI{
    
    [self addSubview:self.img];
    [self.img addSubview:self.dissmissBtn];
    [self.img addSubview:self.titleLabel];
    [self.img addSubview:self.msgLabel];
    [self.img addSubview:self.totalNumLabel];
    [self.img addSubview:self.testTypeLabel];
    [self.img addSubview:self.follewView];
    [self.follewView addSubview:self.totalLabel];
    [self.follewView addSubview:self.tureLabel];
    [self.follewView addSubview:self.falseLabel];
    [self.follewView addSubview:self.otherLabel];
    [self.img addSubview:self.knowBtn];
    [self.img addSubview:self.lookBtn];
    
    [self.img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.equalTo(self);
    }];
    
    [self.dissmissBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.img).with.offset(-ALIGN_WIDTH_PT(15));
        make.top.equalTo(self.img).with.offset(ALIGN_HEIGHT_PT(15));
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(22), ALIGN_WIDTH_PT(22))));
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.img).with.offset(ALIGN_HEIGHT_PT(20));
        make.left.right.equalTo(self.img);
    }];
    
    [self.msgLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom);
        make.left.right.equalTo(self.img);
    }];
    
    [self.totalNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.img.mas_centerX);
        make.top.equalTo(self.msgLabel.mas_bottom);
    }];
    
    [self.testTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.totalNumLabel.mas_centerY);
        make.left.equalTo(self.totalNumLabel.mas_right).with.offset(ALIGN_WIDTH_PT(5));
    }];
    
    [self.follewView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.img).with.offset(ALIGN_WIDTH_PT(10));
        make.right.equalTo(self.img).with.offset(-ALIGN_WIDTH_PT(10));
        make.top.equalTo(self.totalNumLabel.mas_bottom).with.offset(ALIGN_HEIGHT_PT(20));
        make.height.equalTo(@(ALIGN_HEIGHT_PT(145)));
    }];
    
    [self.totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.follewView);
        make.top.equalTo(self.follewView).with.offset(ALIGN_HEIGHT_PT(24));
    }];
    
    [self.tureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.follewView);
        make.top.equalTo(self.totalLabel.mas_bottom).with.offset(ALIGN_HEIGHT_PT(20));
        make.size.equalTo(@(CGSizeMake((SCREEN_WIDTH - ALIGN_WIDTH_PT(75)) / 3, ALIGN_HEIGHT_PT(60))));
    }];
    
    [self.falseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.tureLabel.mas_right);
        make.centerY.equalTo(self.tureLabel.mas_centerY);
        make.size.equalTo(@(CGSizeMake((SCREEN_WIDTH - ALIGN_WIDTH_PT(75)) / 3, ALIGN_HEIGHT_PT(60))));
    }];
    
    [self.otherLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.falseLabel.mas_right);
        make.centerY.equalTo(self.tureLabel.mas_centerY);
        make.size.equalTo(@(CGSizeMake((SCREEN_WIDTH - ALIGN_WIDTH_PT(75)) / 3, ALIGN_HEIGHT_PT(60))));
    }];
    
    [self.knowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.img).with.offset(ALIGN_WIDTH_PT(10));
        make.top.equalTo(self.follewView.mas_bottom).with.offset(ALIGN_HEIGHT_PT(24));
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(145), ALIGN_HEIGHT_PT(40))));
    }];
    
    [self.lookBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.knowBtn.mas_right).with.offset(ALIGN_WIDTH_PT(10));
        make.top.equalTo(self.follewView.mas_bottom).with.offset(ALIGN_HEIGHT_PT(24));
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(145), ALIGN_HEIGHT_PT(40))));
    }];
    
    
    
}

-(void)setModel:(HomeQuestionTestingSubmintModel *)model{
    _model = model;
    
    self.totalNumLabel.text = [NSString stringWithFormat:@"%@分",self.model.totalScore];
    if ([self.model.totalScore floatValue] >= [self.model.passingScore floatValue]){
        self.testTypeLabel.text = @"合格";
        self.testTypeLabel.backgroundColor = COLOR_RGB(73, 176, 118);
    }else{
        self.testTypeLabel.text = @"不合格";
        self.testTypeLabel.backgroundColor = [UIColor redColor];
    }
    
    self.totalLabel.text = [NSString stringWithFormat:@"共答%@题",@([self.model.correctCount intValue] + [self.model.wrongCount intValue])];
    self.tureLabel.text = [NSString stringWithFormat:@"答对 \n %@题",self.model.correctCount];
    self.falseLabel.text = [NSString stringWithFormat:@"答错 \n %@题",self.model.wrongCount];
    self.otherLabel.text = [NSString stringWithFormat:@"部分答对 \n %@题",self.model.partialCorrectCount];
    
    
    
}

#pragma mark -- 点击事件
-(void)respondsTo_dissmissBtn{
    _dissmissBlock();
    
}

-(void)respondsTo_knowBtn{
    _knowBlock();
    
}

-(void)respondsTo_lookBtn{
    _lookBlock();
    
}



#pragma mark -- 懒加载
-(UIImageView *)img{
    if (!_img){
        _img = [UIImageView new];
        _img.image = [UIImage imageNamed:@"backG"];
        _img.layer.cornerRadius = 10;
        _img.layer.masksToBounds = YES;
        _img.userInteractionEnabled = YES;
    }
    return _img;
}

-(UIButton *)dissmissBtn{
    if (!_dissmissBtn){
        _dissmissBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_dissmissBtn setImage:[UIImage imageNamed:@"Frame"] forState:(UIControlStateNormal)];
        [_dissmissBtn addTarget:self action:@selector(respondsTo_dissmissBtn) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _dissmissBtn;
}

-(UILabel *)titleLabel{
    if (!_titleLabel){
        _titleLabel = [UILabel new];
        _titleLabel.text = @"本次考试结果";
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.font = [UIFont systemFontOfSize:22 weight:0.5];
        _titleLabel.textColor = [UIColor blackColor];
    }
    return _titleLabel;
}

-(UILabel *)msgLabel{
    if (!_msgLabel){
        _msgLabel = [UILabel new];
        _msgLabel.text = @"你因违反考场纪律，强制交卷";
        _msgLabel.textAlignment = NSTextAlignmentCenter;
        _msgLabel.font = FONT16;
        _msgLabel.textColor = [UIColor blackColor];
    }
    return _msgLabel;
}




-(UILabel *)totalNumLabel{
    if (!_totalNumLabel){
        _totalNumLabel = [UILabel new];
        _totalNumLabel.textAlignment = NSTextAlignmentCenter;
        _totalNumLabel.font = [UIFont systemFontOfSize:22 weight:0.5];
        _totalNumLabel.textColor = [UIColor blackColor];
    }
    return _totalNumLabel;
}

-(UILabel *)testTypeLabel{
    if (!_testTypeLabel){
        _testTypeLabel = [UILabel new];
        _testTypeLabel.textAlignment = NSTextAlignmentCenter;
        _testTypeLabel.font = FONT14;
        _testTypeLabel.textColor = [UIColor whiteColor];
        _testTypeLabel.layer.cornerRadius = 5;
        _testTypeLabel.layer.masksToBounds = YES;
    }
    return _testTypeLabel;
}



-(UIView *)follewView{
    if (!_follewView){
        _follewView = [UIView new];
        _follewView.backgroundColor = [UIColor whiteColor];
        _follewView.layer.cornerRadius = 10;
        _follewView.layer.masksToBounds = YES;
    }
    return _follewView;
}

-(UILabel *)totalLabel{
    if (!_totalLabel){
        _totalLabel = [UILabel new];
        _totalLabel.text = @"总答题 12 题";
        _totalLabel.textAlignment = NSTextAlignmentCenter;
        _totalLabel.font = FONT15;
        _totalLabel.textColor = [UIColor blackColor];
    }
    return _totalLabel;
}


-(UILabel *)tureLabel{
    if (!_tureLabel){
        _tureLabel = [UILabel new];
        _tureLabel.text = @"答对 \n10题";
        _tureLabel.textAlignment = NSTextAlignmentCenter;
        _tureLabel.font = FONT15;
        _tureLabel.numberOfLines = 2;
        _tureLabel.textColor = [UIColor blackColor];
    }
    return _tureLabel;
}


-(UILabel *)falseLabel{
    if (!_falseLabel){
        _falseLabel = [UILabel new];
        _falseLabel.text = @"答错 \n1题";
        _falseLabel.textAlignment = NSTextAlignmentCenter;
        _falseLabel.font = FONT15;
        _falseLabel.numberOfLines = 2;
        _falseLabel.textColor = [UIColor blackColor];
    }
    return _falseLabel;
}

-(UILabel *)otherLabel{
    if (!_otherLabel){
        _otherLabel = [UILabel new];
        _otherLabel.text = @"部分答对 \n1题";
        _otherLabel.textAlignment = NSTextAlignmentCenter;
        _otherLabel.font = FONT15;
        _otherLabel.numberOfLines = 2;
        _otherLabel.textColor = [UIColor blackColor];
    }
    return _otherLabel;
}


-(UIButton *)knowBtn{
    if (!_knowBtn){
        _knowBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_knowBtn setTitle:@"知道了" forState:(UIControlStateNormal)];
        [_knowBtn setTitleColor:COLOR_RGB(50, 113, 237) forState:(UIControlStateNormal)];
        _knowBtn.layer.cornerRadius = 8;
        _knowBtn.layer.masksToBounds = YES;
        _knowBtn.layer.borderColor = COLOR_RGB(50, 113, 237).CGColor;
        _knowBtn.layer.borderWidth = 1;
        _knowBtn.backgroundColor = [UIColor whiteColor];
        _knowBtn.titleLabel.font = FONT15;
        [_knowBtn addTarget:self action:@selector(respondsTo_knowBtn) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _knowBtn;
}


-(UIButton *)lookBtn{
    if (!_lookBtn){
        _lookBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_lookBtn setTitle:@"查看考试结果" forState:(UIControlStateNormal)];
        [_lookBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        _lookBtn.layer.cornerRadius = 8;
        _lookBtn.layer.masksToBounds = YES;
        _lookBtn.backgroundColor = COLOR_RGB(50, 113, 237);
        _lookBtn.titleLabel.font = FONT15;
        [_lookBtn addTarget:self action:@selector(respondsTo_lookBtn) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _lookBtn;
}





@end
